package me.magicall.myblog.admin.web.springmvc.controllers;

import me.magicall.myblog.front.web.springmvc.controllers.GetOneController;
import me.magicall.myblog.util.UrlPatternRule;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@RequestMapping(method = RequestMethod.GET, //
value = { /* "/admin" + */UrlPatternRule.MODEL_NAME + "/edit",//
})
@Controller("editController")
public class ToEditController {

	@Autowired
	private GetOneController oneController;

	@RequestMapping(UrlPatternRule.ID)
	public void edit(final ModelMap modelMap, @PathVariable("modelName") final String modelName,//
			@PathVariable("id") final long id) {
		oneController.one(modelMap, modelName, id);
	}

	@RequestMapping( { "", "/" })
	public void edit(final ModelMap modelMap, @PathVariable("modelName") final String modelName) {
		edit(modelMap, modelName, 0);
	}
}
